=int(input())
if n>=1000 and n<=9999:
    a=str(n//1000)
    b=str((n%1000)//100)
    c=str((n%100)//10)
    d=str(n%10)
    x1=int(a)
    x2=int(b)
    x3=int(c)
    x4=int(d)
    x5=int(a+b)
    x6=int(b+c)
    x7=int(c+d)
    x8=int(a+b+c)
    x9=int(b+c+d)
    x10=int(a+b+c+d)

    for i in range(2,x1//2+1):
        if x1%i==0:
            x1=0
        else:
            i+=1

    for i in range(2,x2//2+1):
        if x2%i==0:
            x2=0
        else:
            i+=1

    for i in range(2,x3//2+1):
        if x3%i==0:
            x3=0
        else:
            i+=1

    for i in range(2,x4//2+1):
        if x4%i==0:
            x4=0
        else:
            i+=1

    for i in range(2,x5//2+1):
        if x5%i==0:
            x5=0
        else:
            i+=1

    for i in range(2,x6//2+1):
        if x6%i==0:
            x6=0
        else:
            i+=1

    for i in range(2,x7//2+1):
        if x7%i==0:
            x7=0
        else:
            i+=1

    for i in range(2,x8//2+1):
        if x8%i==0:
            x8=0
        else:
            i+=1

    for i in range(2,x9//2+1):
        if x9%i==0:
            x9=0
        else:
            i+=1

    for i in range(2,x10//2+1):
        if x10%i==0:
            x10=0
        else:
            i+=1
    x=max(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10)
    print(x)
else:
    print(0)










